package com.story.modular.app.controller.radio;


import com.baomidou.mybatisplus.plugins.Page;
import com.story.common.persistence.model.AudioDetail;
import com.story.common.persistence.model.VedioCategory;
import com.story.common.persistence.model.VedioDetail;
import com.story.modular.app.constrant.QueryAudioForm;

import com.story.modular.app.constrant.QueryAudioParams;
import com.story.modular.app.dao.AudioDetailDao;
import com.story.modular.app.dao.VedioCategoryDao;

import com.story.modular.app.warpper.VedioWarpper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(value = "app首页专辑列表", description = "app首页专辑列表接口")
@Controller
@RequestMapping(value = "/api/vedio/radio")
public class AppRadioVedioController {


    @Autowired
    private AudioDetailDao audioDetailDao;
    //专辑dao
    @Autowired
    private VedioCategoryDao vedioCategoryDao;


    /**
     * 如果点击的是分类  则出来分类下面的专辑列表
     * 如果点击的是专辑  则把多个专辑显示出来
     */
    @ApiOperation(value="根据分类查询首页专辑列表", notes="根据分类查询首页专辑列表接口")
    @RequestMapping(value = "queryFenleiZhuanji",method = RequestMethod.POST)
    @ResponseBody
    public Object queryFenleiZhuanji(@RequestBody QueryAudioForm queryAudioForm){


        Page<VedioCategory> page = new Page<>(queryAudioForm.getPageNum(),queryAudioForm.getPageSize());
        List<Map<String,Object>> vedioCategoryList=vedioCategoryDao.appGetQueryList(page,queryAudioForm.getFenlei(),
                queryAudioForm.getAge(),queryAudioForm.getPrice(),
                queryAudioForm.getZonghe(),0);
        page.setRecords((List<VedioCategory>) new VedioWarpper(vedioCategoryList).warp());
        return page;
    }
    /**
     * 如果点击的是分类  则出来分类下面的专辑列表
     * 如果点击的是专辑  则把多个专辑显示出来
     */
    @ApiOperation(value="根据多个专辑id查询首页专辑列表", notes="根据多个专辑id查询首页专辑列表接口")
    @RequestMapping(value = "queryzhuanji",method = RequestMethod.POST)
    @ResponseBody
    public Object queryzhuanji(@RequestBody QueryAudioForm queryAudioForm){


        Page<VedioCategory> page = new Page<>(queryAudioForm.getPageNum(),queryAudioForm.getPageSize());
        List<Map<String,Object>> vedioCategoryList=vedioCategoryDao.appGetQueryListZhuanjis(page,queryAudioForm.getZhuanjis(),
                queryAudioForm.getAge(),queryAudioForm.getPrice(),
                queryAudioForm.getZonghe(),0);
        page.setRecords((List<VedioCategory>) new VedioWarpper(vedioCategoryList).warp());
        return page;
    }

    /**
     * 根据专辑查找音频
     */
    @ApiOperation(value="根据专辑id查询音频列表", notes="根据专辑id查询音频列表接口")
    @RequestMapping(value = "queryzhuanjiAudio",method = RequestMethod.POST)
    @ResponseBody
    public Object queryzhuanjiAudio(@RequestBody QueryAudioParams queryAudioParams){


        Page<AudioDetail> page = new Page<>(queryAudioParams.getPageNum(),queryAudioParams.getPageSize());
        List<Map<String,Object>> vedioList=audioDetailDao.getAppVedioList(page,queryAudioParams.getZhuanjiId(),0);
        page.setRecords((List<AudioDetail>) new VedioWarpper(vedioList).warp());
        return page;
    }

    /**
     * 获取vip 专辑列表
     */
    @ApiOperation(value="获取VIP,为您推荐，大家都在听，猜你会听专辑列表", notes="获取VIP专辑列表接口")
    @PostMapping(value = "queryIndexZhuanji")
    @ResponseBody
    public Object queryIndexZhuanji(@ApiParam(name = "pageNum",value = "第几页 默认1")@RequestParam(required=false) Integer pageNum,
                                    @ApiParam(name = "pageSize",value = "每页记录数 默认10")@RequestParam(required=false) Integer pageSize,
                                    @ApiParam(name = "type",value = "查询类型 1VIP 2为您推荐 3大家都在听 4猜你会听",required=true)@RequestParam(required=false) Integer type,
                                    @ApiParam(name = "user",value = "只有type类型是4的时候传  游客用户（设备信息生成id） 登陆用户 返回登陆名") @RequestParam(required=false) String user){

        QueryAudioForm queryAudioForm=new QueryAudioForm();
        Page<VedioCategory> page = new Page<>(pageNum,pageSize);
        List<Map<String,Object>> vedioCategoryList=new ArrayList<>();
        if(pageNum==null){
            pageNum=1;
        }
        if (pageSize==null){
            pageSize=10;
        }

        switch (type){
            case 1:{
                queryAudioForm.setPrice(1);
                vedioCategoryList=vedioCategoryDao.appGetQueryList(page,queryAudioForm.getFenlei(),
                        queryAudioForm.getAge(),queryAudioForm.getPrice(),
                        queryAudioForm.getZonghe(),0);
                break;
            }
            case 2:{
                queryAudioForm.setZonghe(1);
                vedioCategoryList=vedioCategoryDao.appGetQueryList(page,queryAudioForm.getFenlei(),
                        queryAudioForm.getAge(),queryAudioForm.getPrice(),
                        queryAudioForm.getZonghe(),0);
                break;
            }
            //大家都在听
            case 3:{
                vedioCategoryList=vedioCategoryDao.appGetUserQueryList(page,user,
                        type,0);
                page.setRecords((List<VedioCategory>) new VedioWarpper(vedioCategoryList).warp());
                break;

            }
            //4猜你会听
            case 4:{
                vedioCategoryList=vedioCategoryDao.appGetUserQueryList(page,user,
                        type,0);
                page.setRecords((List<VedioCategory>) new VedioWarpper(vedioCategoryList).warp());
                break;
            } default:{

            }
        }





        page.setRecords((List<VedioCategory>) new VedioWarpper(vedioCategoryList).warp());
        return page;
    }



}
